local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),"HomeButton_"..script.Name);
local HomeGui= ClientOHOH.load.UIManager().ui_list.HomeGui
-- 参加一场战斗后 开启

local gUnLockLevel=5


function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

    self:HideButton()

	self.DataStore=self.parent:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent())

    self.ConList={}
    local con= self.parent.UserDataEvent:Connect(function(data)
        if data["buff"] then
            self:UpdBuff(self.DataStore:GetData("buff"))
        end
    end)

    table.insert( self.ConList,con)

    local con2= self.parent.LevelChangeEvent:Connect(function(level)
        self:UpdLevel(level,self.DataStore:GetData("base").rebirth)
	end)
    table.insert( self.ConList,con2)


    self:UpdBuff(self.DataStore:GetData("buff"))
    self:UpdLevel(self.DataStore:GetData("base").level,self.DataStore:GetData("base").rebirth)

end;

function M.HideButton(self)
    HomeGui.insts.Shop.button.Parent.Visible=false
    HomeGui.insts.VipBuy.button.Parent.Visible=false

    
end

function M.ShowButton(self)
    HomeGui.insts.Shop.button.Parent.Visible=true
    HomeGui.insts.VipBuy.button.Parent.Visible=true

    self:dtor()
end

function M.UpdLevel(self,level,rebirth)
    if  rebirth>0 then
        self:ShowButton()
    elseif level>=gUnLockLevel then
        self:ShowButton()
    end

end

function M.UpdBuff(self,buff)
    for k,v in pairs(buff) do
        self:ShowButton()
        return 
    end
end

function M.dtor(self)
     for k,v in pairs(self.ConList) do
        v:Disconnect()
     end
     self.ConList={}
	M.super.dtor(self);
end;

return M